; double potencia(double x, int y);

global potencia

%define x [ebp + 8]
%define y [ebp + 16]

section .text

potencia:
	push ebp
	mov ebp, esp
	push esi
	push edi
	push ebx
	
	finit
	fild dword y ; [y]
	fld qword x ; [x|y]
	fyl2x ; [y*log2(x)]
	fld st0 ; [y*log2(x)|y*log2(x)]
	frndint ; [INT(y*log2(x))|y*log2(x)]
	fsub st1, st0 ; [INT(y*log2(x))|y*log2(x) - INT(y*log2(x))] entonces queda solo la parte fraccionaria.
	fxch st1 ; [FRAC(y*log2(x))|INT(y*log2(x))]
	f2xm1 ; [(2^FRAC(y*log2(x)))-1|INT(y*log2(x))]
	fld1 ; [1|(2^FRAC(y*log2(x)))-1|INT(y*log2(x))]
	faddp st1 ; [2^FRAC(y*log2(x))|INT(y*log2(x))]
	fscale ;  [2^FRAC(y*log2(x)) * 2^(ROUND(INT(y*log2(x))))|INT(y*log2(x))]
	fstp st1 ; [2^(FRAC(y*log2(x))+(ROUND(INT(y*log2(x)))))]
	
fin:
	pop ebx
	pop edi
	pop esi
	pop ebp
	ret
